/**
 * Created by jiangyukun on 2016/5/23.
 */

'use strict';

app.controller('CommunityBoardController', function ($scope, iHttp, $uibModal, DTOptionsBuilder, DTColumnBuilder) {

    $scope.dtOptions = DTOptionsBuilder.newOptions()
        .withOption('lengthChange', false)
        .withOption('searching', false)
        .withOption('ajax', {dataSrc: 'data'})
        .withOption('serverSide', true)
        .withOption('serverData', getServerData);


    $scope.dtColumns = [
        DTColumnBuilder.newColumn('id').withTitle('ID').notVisible(),
        DTColumnBuilder.newColumn('boardName').withTitle('板块名称'),
        DTColumnBuilder.newColumn('allowUserToPost').withTitle('允许用户发贴'),
        DTColumnBuilder.newColumn('icon').withTitle('图标'),
        DTColumnBuilder.newColumn('boardCount').withTitle('板块帖子数'),
        DTColumnBuilder.newColumn('lookCount').withTitle('板块浏览次数'),
        DTColumnBuilder.newColumn('commentCount').withTitle('板块评论次数'),
        DTColumnBuilder.newColumn('likeCount').withTitle('板块点赞次数')
    ];


    $scope.addBoard = addBoard;
    $scope.lookBoard = lookBoard;


    function getServerData(source, data, callback) {
        iHttp.get('mock/json/community-board.json', {data: data}).then(function (result) {
            callback(result.data);
        });
    }

    function addBoard() {
        $uibModal.open({
            templateUrl: 'tpl/community/add_board_dialog.html',
            controller: 'AddBoardController'
        })
    }

    function lookBoard() {
        $uibModal.open({
            templateUrl: 'tpl/community/look_board_dialog.html',
            controller: 'LookBoardController'
        })
    }
});

app.controller('AddBoardController', function ($scope, $uibModalInstance) {
    $scope.close = close;


    function close() {
        $uibModalInstance.close();
    }
});

app.controller('LookBoardController', function ($scope, $uibModalInstance) {
    $scope.close = close;


    function close() {
        $uibModalInstance.close();
    }
});